package dilmaj.client;

import java.util.*;

import javax.jdo.annotations.*;

import dilmaj.shared.CommentVO;
import dilmaj.shared.TermVO;

@PersistenceCapable
public class TermJDO {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;
    
    @Persistent
	private String caption;
    
    @Persistent
    private Long rank;
    
    @Persistent
	private Long privilege;
	
    @Persistent
    private Long userId;
    
    @Persistent
    private String userName;
    
    @Persistent
    private List<Long> areaIDs=new ArrayList<Long>();
    
    @Persistent
	private List<String> userNames=new ArrayList<String>();
	
    @Persistent
	private String suggestion="";
    
    @Persistent
	private String useCase="";
    
    @Persistent
    private List<Long> comments=new ArrayList<Long>();
    
    public TermJDO() {
    
    }
    
    public TermJDO(TermVO termVO) {
    	id=termVO.getId();
    	
    	if (termVO.getCaption()==null)
    		caption="";
    	else
    		caption=termVO.getCaption();
    	
    	if (termVO.getRank()==null) {
    		rank=Long.valueOf(0);
    	} else {
    		rank=termVO.getRank();
    	}
    	
    	if (termVO.getPrivilege()==null) {
    		privilege=Long.valueOf(0);
    	} else {
    		privilege=termVO.getPrivilege();
    	}
    	
    	if (termVO.getUserId()==null)
    		userId=new Long(0);
    	else
    		userId=termVO.getUserId();
    	
    	if (termVO.getUserName()==null)
    		userName="";
    	else
    		userName=termVO.getUserName();
    	
    	if (termVO.getSuggestion()==null)
    		suggestion="";
    	else
    		suggestion=termVO.getSuggestion();
    	
    	if (termVO.getUseCase()==null)
    		useCase="";
    	else
    		useCase=termVO.getUseCase();
    	
    	areaIDs.clear();
    	areaIDs.addAll(termVO.getAreas());
    	
    	userNames.clear();
    	userNames.addAll(termVO.getUsers());
    	
    	comments.clear();
    	comments.addAll(termVO.getComments());
    }
    
    public TermJDO(String caption) {
    	this.caption=caption;
    }
	
	public void setCaption(String newCaption) {
		caption=newCaption;
	}
	
	public Long getId() {
		return id;
	}
	
	public String getCaption() {
		return caption;
	}
	
	public Long getRank() {
		return rank;
	}
	
	public void setRank(long newRank) {
		rank=newRank;
	}
	
	public Long getUserId() {
		return userId;
	}
	
	public void setUserId(Long userId) {
		this.userId=userId;
	}
	
	public void setUserName(String userName) {
		this.userName=userName;
	}
	
	public String getUserName() {
		return userName;
	}
	
	public List<Long> getAreas() {
		return areaIDs;
	}
	
	public void setAreaIDs(List<Long> newIDs) {
		areaIDs.clear();
		areaIDs.addAll(newIDs);
	}
	
	public String getSuggestion() {
		return suggestion;
	}
	
	public String getUseCase() {
		return useCase;
	}
	
	public void setSuggestion(String suggestion) {
		this.suggestion=suggestion;
	}
	
	public void setUseCase(String useCase) {
		this.useCase=useCase;
	}
	
	public void setPrivilege(long newPrivilege) {
		privilege=newPrivilege;
	}
	
	public Long getPrivilege() {
		return privilege;
	}
	
	public List<String> getUsers() {
		return userNames;
	}
	
	public List<Long> getComments() {
		return comments;
	}
	
	public void addUser(String userName) {
		userNames.add(userName);	
	}
	
	public void setUsers(List<String> users) {
		userNames.clear();
		userNames.addAll(users);
	}
	
	public void setComments(List<Long> comments) {
		this.comments.clear();
		this.comments.addAll(comments);
	}
}
